SetupFindNextLine (setupapi)
Last changed: Andriy Klyuchevskyy-131.107.0.111

.
Summary

C# Signature:

[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupFindNextLine(ref INFCONTEXT ContextIn, out INFCONTEXT ContextOut);

VB Signature:

Declare Function SetupFindNextLine Lib "setupapi.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Parameters

ContextIn Pointer to the INF file context retrieved by a call to the SetupFindFirstLine function.
ContextOut Pointer to a variable in which this function returns the context of the found line. ContextOut can point to ContextIn if the caller wishes.

Return Value

If this function finds the next line, the return value is a nonzero value. Otherwise, the return value is zero. To get extended error information, call GetLastError.

Tips & Tricks:

None.

Sample Code:

C#

string infFile = <INF file full path>;
uint ErrorLine = 0;
IntPtr infHandle = SetupOpenInfFile(infFile, null, INF_STYLE_OLDNT | INF_STYLE_WIN4, out ErrorLine);
int iCode = Marshal.GetLastWin32Error();
if (infHandle.ToInt64() != INVALID_HANDLE_VALUE)
{
     Console.WriteLine("INF file was opened successfully.");
     INFCONTEXT Context = new INFCONTEXT();
     if (SetupFindFirstLine(infHandle, "Manufacturer", null, ref Context) == true)
     {
        Console.WriteLine("Manufacturers list:");
        string manufacturerName = "";
        manufacturerName = manufacturerName.PadLeft(256, ' ');
        Int32 requiredSize = manufacturerName.Length;
        SetupGetStringField(ref Context, 1, manufacturerName, manufacturerName.Length, out requiredSize);
        manufacturerName = manufacturerName.Substring(0, requiredSize-1);
        Console.WriteLine(manufacturerName);
        while(SetupFindNextLine(ref Context, out Context) == true)
        {
            manufacturerName = manufacturerName.PadLeft(256, ' ');
            requiredSize = manufacturerName.Length;
            SetupGetStringField(ref Context, 1, manufacturerName, manufacturerName.Length, out requiredSize);
            manufacturerName = manufacturerName.Substring(0, requiredSize - 1);
            Console.WriteLine(manufacturerName);
        }
     }
     else
     {
        Console.WriteLine("Can't find [Manufacturer] section.");
     }
     SetupCloseInfFile(infHandle);
}
else
{
     Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode);
     if (ErrorLine != 0)
     {
        Console.WriteLine("Failure line - {0}.", ErrorLine);
     }
}

Documentation